#include <vector>
#include <iostream>
using namespace std;
class Solution
{
public:
    int removeElement(vector<int> &nums, int val)
    {
        int temp, count = 0, j = 0;
        for (size_t i = 0; i < nums.size(); i++)
        {
            if (nums[i] == val)
            {
                while (nums[j] == val)
                {
                    j += 1;
                }
                count += 1;
                temp = nums[i];
                nums[i] = nums[j];
                nums[j] = temp;
            }
        }
        cout << count << endl;
        for (size_t i = 0; i < nums.size(); i++)
        {
            cout << nums[i] << " ";
        }
        return 0;
    }
};

int main()
{
    Solution test;
    vector<int> nums{3, 2, 2, 3};
    int val = 3;
    test.removeElement(nums, val);
    return 0;
}